from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-18 14:02:39.741386
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 18, Dec, 2022
Time: 14:02:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.2448
Nobs: 874.000 HQIC: -51.5483
Log likelihood: 11537.4 FPE: 3.39778e-23
AIC: -51.7363 Det(Omega_mle): 3.06710e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296243 0.049781 5.951 0.000
L1.Burgenland 0.105569 0.034054 3.100 0.002
L1.Kärnten -0.106845 0.018288 -5.842 0.000
L1.Niederösterreich 0.214690 0.071461 3.004 0.003
L1.Oberösterreich 0.086179 0.067695 1.273 0.203
L1.Salzburg 0.249861 0.036161 6.910 0.000
L1.Steiermark 0.030338 0.047496 0.639 0.523
L1.Tirol 0.127658 0.038658 3.302 0.001
L1.Vorarlberg -0.061834 0.033233 -1.861 0.063
L1.Wien 0.062326 0.060428 1.031 0.302
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064679 0.102365 0.632 0.527
L1.Burgenland -0.009800 0.070027 -0.140 0.889
L1.Kärnten 0.049256 0.037606 1.310 0.190
L1.Niederösterreich -0.173457 0.146947 -1.180 0.238
L1.Oberösterreich 0.362107 0.139203 2.601 0.009
L1.Salzburg 0.286162 0.074358 3.848 0.000
L1.Steiermark 0.108881 0.097667 1.115 0.265
L1.Tirol 0.319010 0.079494 4.013 0.000
L1.Vorarlberg 0.024654 0.068337 0.361 0.718
L1.Wien -0.025513 0.124260 -0.205 0.837
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199910 0.025798 7.749 0.000
L1.Burgenland 0.090193 0.017648 5.111 0.000
L1.Kärnten -0.009166 0.009477 -0.967 0.333
L1.Niederösterreich 0.267697 0.037034 7.228 0.000
L1.Oberösterreich 0.112010 0.035082 3.193 0.001
L1.Salzburg 0.052820 0.018740 2.819 0.005
L1.Steiermark 0.015928 0.024614 0.647 0.518
L1.Tirol 0.102405 0.020034 5.112 0.000
L1.Vorarlberg 0.056763 0.017222 3.296 0.001
L1.Wien 0.112463 0.031316 3.591 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105314 0.026492 3.975 0.000
L1.Burgenland 0.047970 0.018123 2.647 0.008
L1.Kärnten -0.017034 0.009732 -1.750 0.080
L1.Niederösterreich 0.197842 0.038030 5.202 0.000
L1.Oberösterreich 0.276981 0.036026 7.688 0.000
L1.Salzburg 0.117906 0.019244 6.127 0.000
L1.Steiermark 0.100532 0.025276 3.977 0.000
L1.Tirol 0.127296 0.020573 6.187 0.000
L1.Vorarlberg 0.069881 0.017686 3.951 0.000
L1.Wien -0.027493 0.032159 -0.855 0.393
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131766 0.047801 2.757 0.006
L1.Burgenland -0.053867 0.032700 -1.647 0.099
L1.Kärnten -0.037071 0.017561 -2.111 0.035
L1.Niederösterreich 0.166976 0.068619 2.433 0.015
L1.Oberösterreich 0.131683 0.065003 2.026 0.043
L1.Salzburg 0.290922 0.034722 8.378 0.000
L1.Steiermark 0.034700 0.045607 0.761 0.447
L1.Tirol 0.162073 0.037121 4.366 0.000
L1.Vorarlberg 0.108181 0.031911 3.390 0.001
L1.Wien 0.066214 0.058025 1.141 0.254
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060329 0.037878 1.593 0.111
L1.Burgenland 0.038358 0.025912 1.480 0.139
L1.Kärnten 0.049903 0.013915 3.586 0.000
L1.Niederösterreich 0.227693 0.054374 4.188 0.000
L1.Oberösterreich 0.269803 0.051509 5.238 0.000
L1.Salzburg 0.058966 0.027514 2.143 0.032
L1.Steiermark -0.006749 0.036139 -0.187 0.852
L1.Tirol 0.157492 0.029415 5.354 0.000
L1.Vorarlberg 0.069286 0.025286 2.740 0.006
L1.Wien 0.075556 0.045979 1.643 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186426 0.045442 4.103 0.000
L1.Burgenland 0.018480 0.031086 0.594 0.552
L1.Kärnten -0.060338 0.016694 -3.614 0.000
L1.Niederösterreich -0.094083 0.065233 -1.442 0.149
L1.Oberösterreich 0.174045 0.061795 2.817 0.005
L1.Salzburg 0.061127 0.033009 1.852 0.064
L1.Steiermark 0.230262 0.043356 5.311 0.000
L1.Tirol 0.488749 0.035289 13.850 0.000
L1.Vorarlberg 0.051114 0.030336 1.685 0.092
L1.Wien -0.053971 0.055161 -0.978 0.328
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158488 0.051569 3.073 0.002
L1.Burgenland 0.000072 0.035278 0.002 0.998
L1.Kärnten 0.066424 0.018945 3.506 0.000
L1.Niederösterreich 0.201179 0.074029 2.718 0.007
L1.Oberösterreich -0.070986 0.070127 -1.012 0.311
L1.Salzburg 0.220466 0.037460 5.885 0.000
L1.Steiermark 0.112786 0.049202 2.292 0.022
L1.Tirol 0.084493 0.040047 2.110 0.035
L1.Vorarlberg 0.123694 0.034427 3.593 0.000
L1.Wien 0.105098 0.062599 1.679 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358125 0.030482 11.749 0.000
L1.Burgenland 0.006969 0.020852 0.334 0.738
L1.Kärnten -0.025472 0.011198 -2.275 0.023
L1.Niederösterreich 0.230719 0.043757 5.273 0.000
L1.Oberösterreich 0.155942 0.041451 3.762 0.000
L1.Salzburg 0.052806 0.022142 2.385 0.017
L1.Steiermark -0.016797 0.029083 -0.578 0.564
L1.Tirol 0.122634 0.023671 5.181 0.000
L1.Vorarlberg 0.071296 0.020349 3.504 0.000
L1.Wien 0.045239 0.037001 1.223 0.221
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038692 0.160323 0.181999 0.168742 0.142275 0.127984 0.065700 0.218767
Kärnten 0.038692 1.000000 0.001488 0.132024 0.026943 0.099397 0.432623 -0.049290 0.101281
Niederösterreich 0.160323 0.001488 1.000000 0.346882 0.170395 0.312896 0.128227 0.191845 0.340758
Oberösterreich 0.181999 0.132024 0.346882 1.000000 0.234891 0.342292 0.178215 0.180218 0.273666
Salzburg 0.168742 0.026943 0.170395 0.234891 1.000000 0.153512 0.137352 0.153082 0.140637
Steiermark 0.142275 0.099397 0.312896 0.342292 0.153512 1.000000 0.160257 0.148205 0.093952
Tirol 0.127984 0.432623 0.128227 0.178215 0.137352 0.160257 1.000000 0.123140 0.164205
Vorarlberg 0.065700 -0.049290 0.191845 0.180218 0.153082 0.148205 0.123140 1.000000 0.019300
Wien 0.218767 0.101281 0.340758 0.273666 0.140637 0.093952 0.164205 0.019300 1.000000